#pragma strict

public var rotateby : Vector3;
public var offsetby : Vector3;
public var attachto : Transform = null;

function Start()
{
	if(attachto)
	{
	attachTo(attachto);
	}
}

function attachTo(attachto) 
{
	transform.parent = attachto;
	transform.localPosition = Vector3.zero;
	transform.localPosition += offsetby;
	transform.localRotation = Quaternion.identity;
	transform.localRotation *= Quaternion.Euler(rotateby);
	transform.localScale = Vector3.one;
}

function attachTo(attachto, attachobj : GameObject) 
{
	if(!attachto) return;
	transform.parent = attachto;
	transform.localPosition = Vector3.zero;
	transform.localPosition += offsetby;
	transform.localRotation = Quaternion.identity;
	transform.localRotation *= Quaternion.Euler(rotateby);
	transform.localScale = Vector3.one;
	
	if(GetComponent(Collider) && attachobj && attachobj.GetComponent(Collider))
	{
		Physics.IgnoreCollision(collider, attachobj.collider);
	}
	if(GetComponent(Rigidbody))
	{
		rigidbody.isKinematic = true;
		rigidbody.useGravity = false;
	}
}